const express = require('express');
const router = express.Router();

const fileupload = require('../../controller/upload')
const MAO = require('multer-aliyun-oss')
const multer = require('multer')

    // // 上传OSS配置
    // const upload = multer({
    //     storage: MAO({
    //         config: {
    //             region: 'oss-cn-shenzhen',
    //             accessKeyId: 'LTAI5tG3pchVxj6pjqEpXuRe',
    //             accessKeySecret: 'WnweDoDQAcfFyOMbrAkgzFpUdjxuXz',
    //             bucket: 'baigei'
    //         }
    //     })
    // })

    // //上传OSS配置
    // const upload = multer({
    //     storage: MAO({
    //         config: {
    //             region: 'oss-cn-shenzhen',
    //             accessKeyId: 'LTAI5tLBxQCbAVYHAjrRmBzz',
    //             accessKeySecret: 'wUqVKZHAWdeEMp3fCN2rEU8uQcGoaP',
    //             bucket: 'task-uploads'
    //         }
    //     })
    // })

//上传文件夹配置
function add0(m) { return m < 10 ? '0' + m : m }
var time = new Date();
var y = time.getFullYear();
var m = time.getMonth() + 1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
m = add0(m)
d = add0(d)
h = add0(h)
const upload = multer({
    dest: 'uploads/' + y + '/' + m + '/' + d + '/'
})

// 上传
router.post('/upload', upload.array('files', 9), fileupload.updata)
    // 下载
router.post('/download/:taskId', fileupload.download)

module.exports = router